import React, { Component } from 'react'
import {connect} from 'react-redux'
import {increment,decrement} from '../../redux/actions/counter.js'

class Counter extends Component {
    increment=()=>{
        this.props.increment(2)
    }
    decrement=()=>{
        this.props.decrement(3)
    }
    render() {
        const {num,todos}=this.props;
        return (
            <div className="container">
				<h4 className='display-4'>当前值为 {num}</h4>
				<button onClick={this.increment} className="mr-2 btn btn-primary">增加</button>
				<button onClick={this.decrement} className="btn btn-danger">减少</button>
			    <p className="mt-2">新闻总条数为{todos.length}</p>
            </div>
        )
    }
}

const mapState=(state)=>({num:state.counter.num,todos:state.todo})
const mapDispatch={increment,decrement}

export default connect(mapState,mapDispatch)(Counter)